Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Jan 13, 2026

Describe your change:

Count number of palindromic substrings in a string

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary by CodeRabbit

  • Documentation

    • Added detailed guides for palindromic substring problems and a new scheduling problem; reorganized Pascal's Triangle into Dynamic Programming and removed duplicate palindrome docs.
  • New Features

    • Added palindrome-counting and task-scheduling utilities.
  • Tests

    • Added unit tests validating palindrome algorithms and the scheduling utility.
  • Style

    • Minor documentation formatting improvements.

✏️ Tip: You can customize this high-level summary in your review settings.

@BrianLusina BrianLusina self-assigned this Jan 13, 2026
@BrianLusina BrianLusina added enhancement Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates Strings Dynamic Programming Dynamic Programming algorithm labels Jan 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

Reorganizes palindromic substring content into a new Dynamic Programming subsection, adds DP implementations and tests for counting palindromic substrings, introduces a longest-palindrome test, adds a new heap-based Schedule Tasks module and tests, and makes small documentation formatting updates.

Changes

Cohort / File(s) Summary
Directory & Index Updates
DIRECTORY.md
Added Palindromic Substring and Pascals Triangle under Dynamic Programming; removed Longest Palindromic Substring from Two Pointers section; added Heap section under Spread Stones.
Palindromic Substring — docs & README
algorithms/dynamic_programming/palindromic_substring/README.md
New README documenting Palindromic Substring and Longest Palindromic Substring problems with DP solution outlines, examples, and complexity notes.
Palindromic Substring — implementations
algorithms/dynamic_programming/palindromic_substring/__init__.py
Added count_palindromic_substrings(s: str) -> int and count_palindromic_substrings_2(s: str) -> int — two DP-based counting implementations (O(n²) time/space).
Longest Palindromic Substring — function
algorithms/dynamic_programming/palindromic_substring/longest_palindromic_substring.py
Adjusted import to algorithms.two_pointers.palindrome.is_palindrome; moved former docstring text into a literal inside the function (docstring changed).
Palindromic Substring — tests
algorithms/dynamic_programming/palindromic_substring/test_palindromic_substring.py, algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py
Added parameterized unit tests for both counting functions and for longest_palindromic_substring.
Two Pointers README change
algorithms/two_pointers/palindrome/README.md
Removed the Longest Palindromic Substring section from this README.
Pascal's Triangle doc tweak
algorithms/dynamic_programming/pascals_triangle/__init__.py
Minor docstring formatting change in sequence representation.
Schedule Tasks (Heap) — docs & implementation
algorithms/heap/schedule_tasks/README.md, algorithms/heap/schedule_tasks/__init__.py
New README and implementation minimum_machines(tasks: List[List[int]]) -> int using sorting + min-heap to compute minimum machines (O(n log n)).
Schedule Tasks — tests
algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py
Added parameterized unit tests for minimum_machines.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

Heap

Poem

🐰 I hopped through code with joy and cheer,
Palindromes nested, neatly near,
Heaps lined up machines to keep,
Tests awake while functions sleep,
Hooray — the algorithms spring a cheer! 🥕

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'feat(algorithms, dynamic programming): dynamic programming problems' is overly broad and generic. It uses vague language like 'dynamic programming problems' without clearly identifying the primary changes, which include palindromic substrings, Pascal's Triangle reorganization, and heap scheduling tasks. Refine the title to be more specific about the main contributions, such as 'feat: add palindromic substring DP algorithms and heap scheduling tasks' or focus on the primary change if one is intended.
Description check ❓ Inconclusive The description is partially complete but contains inaccuracies. While the author checked multiple boxes suggesting they added algorithms, fixed bugs, and made documentation changes, the description only mentions 'Count number of palindromic substrings in a string' and omits discussion of other significant changes (Pascal's Triangle reorganization, heap scheduling tasks, and removal of palindromic substring from Two Pointers). Update the description to comprehensively document all changes: the palindromic substring algorithms, Pascal's Triangle relocation, heap scheduling implementation, and relevant documentation updates to match the extensive changes reflected in the actual commit.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
algorithms/dynamic_programming/palindromic_substring/longest_palindromic_substring.py (1)

32-32: Critical bug: i + i should be i + 1.

When setting the result bounds for a two-character palindrome, the end index calculation is incorrect. For phrase[i] == phrase[i + 1], the palindrome spans indices [i, i + 1], not [i, i + i].

Example: For input "aa", when i=0:

  • Current: result = [0, 0] → returns "a"
  • Expected: result = [0, 1] → returns "aa"
🐛 Proposed fix
         if phrase[i] == phrase[i + 1]:
             dp[i][i + 1] = True
-            result = [i, i + i]
+            result = [i, i + 1]
🤖 Fix all issues with AI agents
In @algorithms/dynamic_programming/palindromic_substring/README.md:
- Around line 68-69: Update the sentence that currently reads "lengths greater
than three" to "lengths greater than two" in the README explanation so it
correctly matches the algorithm description (base cases for lengths 1 and 2,
loop starts at length 3); ensure the surrounding text still reads naturally
after this single-word change.

In
@algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py:
- Around line 7-15: Add missing edge-case tests to
LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES by including ("", ""), ("a", "a"), and
a length-2 palindrome case such as ("aab", "aa"); also fix the off-by-one bug in
longest_palindromic_substring.py where the center-expansion result is set with
result = [i, i + i] — change it to result = [i, i + 1] so two-character
palindromes are handled correctly (search for the variable name result and the
incorrect assignment to locate the fix).
🧹 Nitpick comments (1)
algorithms/dynamic_programming/palindromic_substring/__init__.py (1)

34-66: Consider documenting the difference between the two implementations.

Both functions produce identical results but use slightly different iteration patterns. The second function uses boolean arithmetic (count += dp[i][j]) which is a nice Pythonic touch.

It would be helpful to add a brief note in the docstring or a module-level comment explaining why two implementations exist (e.g., for educational purposes, different iteration order, etc.).

📝 Suggested docstring enhancement
 def count_palindromic_substrings_2(s: str) -> int:
     """
     Counts the number of palindromic substrings that can be found in the given string
+
+    This is an alternative implementation that iterates by substring length
+    rather than by difference between indices. Both approaches have the same
+    O(n²) time and space complexity.
+
     Args:
         s(str): string to check for palindromic substrings
     Returns:
         int: number of palindromic substrings
     """
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72a999a and 780f9dc.

⛔ Files ignored due to path filters (19)
  • algorithms/dynamic_programming/palindromic_substring/images/examples/palindromic_substring_example_1.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/examples/palindromic_substring_example_2.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_1.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_10.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_11.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_12.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_13.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_14.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_15.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_16.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_17.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_2.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_3.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_4.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_5.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_6.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_7.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_8.png is excluded by !**/*.png
  • algorithms/dynamic_programming/palindromic_substring/images/solutions/palindromic_substring_solution_9.png is excluded by !**/*.png
📒 Files selected for processing (10)
  • DIRECTORY.md
  • algorithms/dynamic_programming/palindromic_substring/README.md
  • algorithms/dynamic_programming/palindromic_substring/__init__.py
  • algorithms/dynamic_programming/palindromic_substring/longest_palindromic_substring.py
  • algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py
  • algorithms/dynamic_programming/palindromic_substring/test_palindromic_substring.py
  • algorithms/dynamic_programming/pascals_triangle/README.md
  • algorithms/dynamic_programming/pascals_triangle/__init__.py
  • algorithms/dynamic_programming/pascals_triangle/test_pascals_triangle.py
  • algorithms/two_pointers/palindrome/README.md
💤 Files with no reviewable changes (1)
  • algorithms/two_pointers/palindrome/README.md
🧰 Additional context used
🧬 Code graph analysis (1)
algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py (1)
algorithms/dynamic_programming/palindromic_substring/longest_palindromic_substring.py (1)
  • longest_palindromic_substring (4-42)
🪛 LanguageTool
algorithms/dynamic_programming/palindromic_substring/README.md

[style] ~23-~23: Consider a more expressive alternative.
Context: ...results of the earlier computations. To do this, we can create a lookup table, dp,...

(DO_ACHIEVE)


[style] ~43-~43: Using many exclamation marks might seem excessive (in this case: 15 exclamation marks for a text that’s 5567 characters long)
Context: ...s/palindromic_substring_solution_1.png) Solution 2 Solution 3 Solution 4 Solution 5 Solution 6 Solution 7 Solution 8 Solution 9 Solution 10 Solution 11 Solution 12 Solution 13 Solution 14 Solution 15 ![Solution 16](./images/solutions/palindr...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.18.1)
algorithms/dynamic_programming/palindromic_substring/README.md

23-23: Reference links and images should use a label that is defined
Missing link or image reference definition: "j"

(MD052, reference-links-images)


24-24: Reference links and images should use a label that is defined
Missing link or image reference definition: "j"

(MD052, reference-links-images)


33-33: Reference links and images should use a label that is defined
Missing link or image reference definition: "i+1"

(MD052, reference-links-images)


34-34: Reference links and images should use a label that is defined
Missing link or image reference definition: "i+1"

(MD052, reference-links-images)


38-38: Reference links and images should use a label that is defined
Missing link or image reference definition: "1"

(MD052, reference-links-images)


40-40: Reference links and images should use a label that is defined
Missing link or image reference definition: "2"

(MD052, reference-links-images)

DIRECTORY.md

72-72: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


73-73: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


74-74: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


75-75: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


76-76: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


77-77: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)

🔇 Additional comments (7)
algorithms/dynamic_programming/pascals_triangle/__init__.py (1)

32-32: LGTM!

Minor docstring formatting improvement - using ... instead of ...... for the sequence representation is cleaner and more conventional.

algorithms/dynamic_programming/palindromic_substring/test_palindromic_substring.py (1)

1-34: LGTM!

Well-structured test module with comprehensive parameterized test cases covering:

  • Single character strings (each char is a palindrome)
  • All same characters ("aaa", "zzz", "wwwwwwwwww")
  • Mixed strings with various palindromic patterns
  • Known palindrome word ("tattarrattat")

The test values are mathematically correct (e.g., "wwwwwwwwww" with 10 chars yields 55 palindromic substrings = n*(n+1)/2).

DIRECTORY.md (1)

72-77: LGTM!

The new directory entries correctly document the added palindromic substring and Pascal's triangle files. The indentation follows the existing pattern used throughout the file.

algorithms/dynamic_programming/palindromic_substring/longest_palindromic_substring.py (1)

1-1: Import path is correct.

The is_palindrome function is properly exported from algorithms.two_pointers.palindrome (defined in __init__.py at line 1). The import statement is valid and will work as intended.

algorithms/dynamic_programming/palindromic_substring/README.md (1)

15-16: All referenced images are present in the repository. The image files at ./images/examples/ (example_1.png, example_2.png) and ./images/solutions/ (solution_1.png through solution_17.png) have been included in the PR.

algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py (1)

18-22: LGTM!

The test class structure and parameterized test method are well-implemented. Using @parameterized.expand is the right approach for data-driven tests.

algorithms/dynamic_programming/palindromic_substring/__init__.py (1)

1-31: LGTM!

The DP implementation is correct. The algorithm properly:

  1. Initializes all single-character substrings as palindromes
  2. Checks adjacent pairs for length-2 palindromes
  3. Expands to longer lengths using the recurrence relation dp[i][j] = (s[i] == s[j]) and dp[i+1][j-1]

Time complexity is O(n²) and space complexity is O(n²), which is appropriate for this DP approach.

Comment on lines +68 to +69
3. After these base cases, the algorithm checks all possible substrings of lengths greater than three. However, it only
compares the first and last characters, and the rest of the substring is checked using the lookup table.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor text inconsistency: "three" should be "two".

The solution summary states "lengths greater than three" but should say "lengths greater than two" to be consistent with the algorithm description. Base cases handle lengths 1 and 2, so the loop checks lengths starting from 3 (i.e., greater than 2).

📝 Suggested fix
-3. After these base cases, the algorithm checks all possible substrings of lengths greater than three. However, it only
+3. After these base cases, the algorithm checks all possible substrings of lengths greater than two. However, it only
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
3. After these base cases, the algorithm checks all possible substrings of lengths greater than three. However, it only
compares the first and last characters, and the rest of the substring is checked using the lookup table.
3. After these base cases, the algorithm checks all possible substrings of lengths greater than two. However, it only
compares the first and last characters, and the rest of the substring is checked using the lookup table.
🤖 Prompt for AI Agents
In @algorithms/dynamic_programming/palindromic_substring/README.md around lines
68 - 69, Update the sentence that currently reads "lengths greater than three"
to "lengths greater than two" in the README explanation so it correctly matches
the algorithm description (base cases for lengths 1 and 2, loop starts at length
3); ensure the surrounding text still reads naturally after this single-word
change.

Comment on lines +7 to +15
LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES = [
("mnm", "mnm"),
("zzz", "zzz"),
("cat", "c"),
("lever", "eve"),
("xyxxyz", "yxxy"),
("wwwwwwwwww", "wwwwwwwwww"),
("tattarrattat", "tattarrattat"),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add edge cases for empty string, single character, and length-2 palindromes.

The test suite is missing edge cases that could expose bugs in the implementation:

  • Empty string ""
  • Single character "a"
  • String where the longest palindrome is exactly 2 characters (e.g., "aab""aa")

The last case is particularly important because the implementation in longest_palindromic_substring.py has a bug on line 29: result = [i, i + i] should be result = [i, i + 1]. This bug would cause incorrect results when the longest palindrome is exactly 2 characters, but none of the current test cases would catch it.

🧪 Suggested additional test cases
 LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES = [
+    ("", ""),
+    ("a", "a"),
+    ("aab", "aa"),
+    ("baa", "aa"),
     ("mnm", "mnm"),
     ("zzz", "zzz"),
     ("cat", "c"),
     ("lever", "eve"),
     ("xyxxyz", "yxxy"),
     ("wwwwwwwwww", "wwwwwwwwww"),
     ("tattarrattat", "tattarrattat"),
 ]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES = [
("mnm", "mnm"),
("zzz", "zzz"),
("cat", "c"),
("lever", "eve"),
("xyxxyz", "yxxy"),
("wwwwwwwwww", "wwwwwwwwww"),
("tattarrattat", "tattarrattat"),
]
LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES = [
("", ""),
("a", "a"),
("aab", "aa"),
("baa", "aa"),
("mnm", "mnm"),
("zzz", "zzz"),
("cat", "c"),
("lever", "eve"),
("xyxxyz", "yxxy"),
("wwwwwwwwww", "wwwwwwwwww"),
("tattarrattat", "tattarrattat"),
]
🤖 Prompt for AI Agents
In
@algorithms/dynamic_programming/palindromic_substring/test_longest_palindromic_substring.py
around lines 7 - 15, Add missing edge-case tests to
LONGEST_PALINDROMIC_SUBSTRING_TEST_CASES by including ("", ""), ("a", "a"), and
a length-2 palindrome case such as ("aab", "aa"); also fix the off-by-one bug in
longest_palindromic_substring.py where the center-expansion result is set with
result = [i, i + i] — change it to result = [i, i + 1] so two-character
palindromes are handled correctly (search for the variable name result and the
incorrect assignment to locate the fix).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@algorithms/heap/schedule_tasks/README.md`:
- Line 16: The constraint uses inconsistent notation `tasksi.start` and
`tasksi.end`; change them to consistent, standard subscript/index notation such
as `tasks[i].start` and `tasks[i].end` (or `tasks_i.start`/`tasks_i.end` if you
prefer subscripts) so the constraint reads "0 <= tasks[i].start < tasks[i].end
<= 10^4".

In `@algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py`:
- Line 17: Update the failing test case tuple in
test_schedule_tasks_on_minimum_machines.py where the input intervals ([[5, 6],
[6, 7], [1, 7], [10, 14], [8, 13]], 4) has the wrong expected value; change the
expected value from 4 to 2 so the tuple becomes ([[5, 6], [6, 7], [1, 7], [10,
14], [8, 13]], 2) to match the algorithm's output.
🧹 Nitpick comments (2)
algorithms/heap/schedule_tasks/__init__.py (2)

9-11: Redundant heapify call on an empty list.

Calling heapify on an empty list is unnecessary since an empty list is already a valid heap. This is harmless but adds minor overhead.

♻️ Suggested simplification
     # initialize a min heap to keep track of the end times
     machines: List[int] = []
-    heapify(machines)

5-22: Consider the side effect of in-place sorting.

The function modifies the input tasks list via tasks.sort(). While this is noted in the comment for performance reasons, callers may not expect their input to be mutated. Consider documenting this behavior in a docstring or using sorted() if input immutability is preferred.

Otherwise, the algorithm implementation is correct and efficient.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 780f9dc and 24025fa.

⛔ Files ignored due to path filters (23)
  • algorithms/heap/schedule_tasks/images/examples/schedule_tasks_on_minimum_machines_example_1.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/examples/schedule_tasks_on_minimum_machines_example_2.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/examples/schedule_tasks_on_minimum_machines_example_3.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/examples/schedule_tasks_on_minimum_machines_example_4.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_1.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_10.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_11.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_12.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_13.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_14.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_15.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_16.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_17.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_18.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_19.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_2.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_3.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_4.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_5.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_6.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_7.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_8.png is excluded by !**/*.png
  • algorithms/heap/schedule_tasks/images/solutions/schedule_tasks_on_minimum_machines_solution_9.png is excluded by !**/*.png
📒 Files selected for processing (5)
  • DIRECTORY.md
  • algorithms/heap/__init__.py
  • algorithms/heap/schedule_tasks/README.md
  • algorithms/heap/schedule_tasks/__init__.py
  • algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py
🧰 Additional context used
🧬 Code graph analysis (2)
algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py (1)
algorithms/heap/schedule_tasks/__init__.py (1)
  • minimum_machines (5-23)
algorithms/heap/schedule_tasks/__init__.py (2)
algorithms/sorting/heapsort/__init__.py (1)
  • heapify (60-63)
puzzles/grade_school/__init__.py (1)
  • sort (15-19)
🪛 LanguageTool
algorithms/heap/schedule_tasks/README.md

[style] ~44-~44: Using many exclamation marks might seem excessive (in this case: 19 exclamation marks for a text that’s 4104 characters long)
Context: ...sks_on_minimum_machines_solution_1.png) Solution 2 Solution 3 Solution 4 Solution 5 Solution 6 Solution 7 Solution 8 Solution 9 Solution 10 Solution 11 Solution 12 Solution 13 Solution 14 Solution 15 Solution 16 Solution 17 ![Solution 18](images/solutions/schedule_...

(EN_EXCESSIVE_EXCLAMATION)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md

72-72: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


73-73: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


74-74: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


75-75: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


76-76: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


77-77: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)


140-140: Unordered list indentation
Expected: 0; Actual: 2

(MD007, ul-indent)


141-141: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


142-142: Unordered list indentation
Expected: 4; Actual: 6

(MD007, ul-indent)

🔇 Additional comments (4)
algorithms/heap/schedule_tasks/README.md (1)

25-78: Documentation looks good!

The solution explanation is clear, the algorithm steps are well-documented, and the time/space complexity analysis is accurate. The O(n log n) time complexity from sorting plus heap operations and O(n) space complexity for the heap are correctly stated.

algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py (1)

6-16: Good test coverage for the algorithm.

The test cases cover important scenarios:

  • Overlapping intervals requiring multiple machines
  • Non-overlapping sequential tasks (single machine)
  • All tasks with identical time ranges (maximum machines)
  • Tasks that can be chained (finish time equals next start time)
DIRECTORY.md (2)

72-77: New directory entries look correct.

The Palindromic Substring and Pascals Triangle entries under Dynamic Programming are properly added and link to the correct file paths. The indentation follows the existing pattern in this file.


140-142: Heap section entry is correct.

The new Heap section with Schedule Tasks entry correctly reflects the new module added in this PR.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


- n == `tasks.length`
- 1 <= `tasks.length` <= 10^3
- 0 <= `tasksi.start` < `tasksi.end` <= 10^4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor typo in constraint notation.

The constraint tasksi.start and tasksi.end should use subscript notation consistently, such as tasks[i].start or tasks_i.start.

📝 Suggested fix
-  - 0 <= `tasksi.start` < `tasksi.end` <= 10^4
+  - 0 <= `tasks[i].start` < `tasks[i].end` <= 10^4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 0 <= `tasksi.start` < `tasksi.end` <= 10^4
- 0 <= `tasks[i].start` < `tasks[i].end` <= 10^4
🤖 Prompt for AI Agents
In `@algorithms/heap/schedule_tasks/README.md` at line 16, The constraint uses
inconsistent notation `tasksi.start` and `tasksi.end`; change them to
consistent, standard subscript/index notation such as `tasks[i].start` and
`tasks[i].end` (or `tasks_i.start`/`tasks_i.end` if you prefer subscripts) so
the constraint reads "0 <= tasks[i].start < tasks[i].end <= 10^4".

([[1, 3], [3, 5], [5, 9], [9, 12], [12, 13], [13, 16], [16, 17]], 1),
([[1, 3], [2, 6], [5, 9], [4, 7], [8, 10], [8, 10], [12, 15]], 3),
([[5, 6], [5, 6], [5, 6], [5, 6], [6, 7]], 4),
([[5, 6], [6, 7], [1, 7], [10, 14], [8, 13]], 4),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cd algorithms/heap/schedule_tasks && find . -type f -name "*.py" | head -20

Repository: BrianLusina/PythonSnips

Length of output: 125


🏁 Script executed:

cd algorithms/heap/schedule_tasks && git ls-files | grep -E "(\.py$)" | head -20

Repository: BrianLusina/PythonSnips

Length of output: 121


🏁 Script executed:

cat -n algorithms/heap/schedule_tasks/__init__.py

Repository: BrianLusina/PythonSnips

Length of output: 1060


🏁 Script executed:

cat -n algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py | head -40

Repository: BrianLusina/PythonSnips

Length of output: 1463


🏁 Script executed:

cd algorithms/heap/schedule_tasks && python3 << 'EOF'
from __init__ import minimum_machines

tasks = [[5, 6], [6, 7], [1, 7], [10, 14], [8, 13]]
result = minimum_machines(tasks.copy())
print(f"Tasks: {[[5, 6], [6, 7], [1, 7], [10, 14], [8, 13]]}")
print(f"Actual result: {result}")
print(f"Expected in test: 4")
print(f"Test passes: {result == 4}")
EOF

Repository: BrianLusina/PythonSnips

Length of output: 153


🏁 Script executed:

cd algorithms/heap/schedule_tasks && python3 << 'EOF'
import sys
sys.path.insert(0, '/dev/null')  # prevent import issues

from heapq import heappush, heappop, heapify
from typing import List

def minimum_machines(tasks: List[List[int]]) -> int:
    tasks.sort(key=lambda x: x[0])
    machines: List[int] = []
    heapify(machines)
    
    for current_task in tasks:
        task_start, task_end = current_task
        if machines and machines[0] <= task_start:
            heappop(machines)
        heappush(machines, task_end)
    return len(machines)

# Test the problematic case
tasks = [[5, 6], [6, 7], [1, 7], [10, 14], [8, 13]]
result = minimum_machines(tasks)
print(f"Result: {result}")
print(f"Expected: 4")
EOF

Repository: BrianLusina/PythonSnips

Length of output: 88


Fix incorrect expected value in test case at line 17.

The test case ([[5, 6], [6, 7], [1, 7], [10, 14], [8, 13]], 4) has an incorrect expected value. The algorithm returns 2 machines, not 4.

When sorted by start time: [[1,7], [5,6], [6,7], [8,13], [10,14]]

  • [1,7]: allocate machine, machines=[7]
  • [5,6]: 7 > 5, allocate new machine, machines=[6,7]
  • [6,7]: 6 <= 6, reuse machine, machines=[7,7]
  • [8,13]: 7 <= 8, reuse machine, machines=[7,13]
  • [10,14]: 7 <= 10, reuse machine, machines=[13,14]

Result: 2 machines.

Change the expected value from 4 to 2.

🤖 Prompt for AI Agents
In `@algorithms/heap/schedule_tasks/test_schedule_tasks_on_minimum_machines.py` at
line 17, Update the failing test case tuple in
test_schedule_tasks_on_minimum_machines.py where the input intervals ([[5, 6],
[6, 7], [1, 7], [10, 14], [8, 13]], 4) has the wrong expected value; change the
expected value from 4 to 2 so the tuple becomes ([[5, 6], [6, 7], [1, 7], [10,
14], [8, 13]], 2) to match the algorithm's output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Datastructures Datastructures Documentation Documentation Updates Dynamic Programming Dynamic Programming algorithm enhancement Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants